<template>
  <div id="travel">
    <!-- 头部搜索 -->
    <header>
      <div class="topSec">
        <van-icon name="arrow-left" @click="goBack" />
        <van-search
          v-model="value"
          :label="address"
          placeholder="想去哪里，搜一搜~"
          shape="round"
          background="transparent"
        >
        </van-search>
        <van-icon name="arrow-down" />
      </div>
      <div class="aim">
        <van-cell title="目的地推荐" is-link value="更多" />
      </div>
      <div class="select">
        <p>
          <span :class="{ active: active == 0 }" @click="active = 0">精选</span>
          <span :class="{ active: active == 1 }" @click="active = 1"
            >赏秋好去处</span
          >
        </p>
        <div class="content">
          <div v-if="active == 0" class="tab1">
            <div v-for="item in aimList" :key="item.id">
              <img :src="getPictureSrc(item.url)" alt="" />
              <span>{{ item.title }}</span>
            </div>
          </div>
          <div v-if="active == 1">内容二</div>
        </div>
      </div>
    </header>
    <!-- 亲子出游 -->
    <div class="parCam">
      <div>
        <div v-for="item in parCam" :key="item.url">
          <p>{{ item.title }}</p>
          <img :src="item.url" alt="" />
        </div>
      </div>
      <p>附近有13家酒店推荐<span>最近距您1.3km</span></p>
    </div>
    <!-- 全新旅游体验 -->
    <div class="newTrav">
      <h2>全新旅游体验</h2>
      <ul class="list1">
        <li>
          <img src="../assets/zyzImg/lv1.png" alt="" />
          <p>西藏自驾游</p>
        </li>
        <li>
          <img src="../assets/zyzImg/lv2.png" alt="" />
          <p>休闲时光</p>
        </li>
      </ul>
      <div class="list2">
        <div class="left">
          <div v-for="item in mainListLeft" :key="item.id">
            <img :src="getPictureSrc(item.url)" alt="" />
            <div class="info">
              <p>{{ item.title }}</p>
              <p>
                <van-icon name="smile-o" />
                <span>{{ item.name }}</span>
                <em
                  ><van-icon name="like-o" /> <span>{{ item.praise }}</span></em
                >
              </p>
            </div>
          </div>
        </div>
        <div class="right">
          <div v-for="item in mainListRight" :key="item.id">
            <img :src="getPictureSrc(item.url)" alt="" />
            <div class="info">
              <p>{{ item.title }}</p>
            </div>
          </div>
        </div>
      </div>
      <div class="bottom">
        <p>没有更多了...</p>
      </div>
    </div>
    <footer>
      <van-tabbar fixed>
        <van-tabbar-item icon="wap-home-o">首页</van-tabbar-item>
        <van-tabbar-item icon="orders-o">游记</van-tabbar-item>
        <van-tabbar-item icon="guide-o">攻略</van-tabbar-item>
        <van-tabbar-item icon="manager-o">我的</van-tabbar-item>
      </van-tabbar>
    </footer>
  </div>
</template>
<script>
import { ref, computed } from "vue";
import {
  Search,
  Icon,
  Cell,
  CellGroup,
  Tab,
  Tabs,
  Tabbar,
  TabbarItem,
} from "vant";
import { useRouter, useRoute } from "vue-router";
import { useStore } from "vuex";
export default {
  name: "Travel",
  components: {
    [Search.name]: Search,
    [Icon.name]: Icon,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Tab.name]: Tab,
    [Tabs.name]: Tabs,
    [Tabbar.name]: Tabbar,
    [TabbarItem.name]: TabbarItem,
  },
  setup() {
    const { goBack, value } = header();
    const active = ref(0);
    // 获取store数据
    const store = useStore();
    store.dispatch("travel/travelData");
    function getPictureSrc(url) {
      let reg = /zyzImg\/(.*).png$/;
      let str = url;
      if (reg.test(url)) {
        let res = str.match(reg)[1];
        return require("../assets/zyzImg/" + res + ".png");
      } else {
        return url;
      }
    }
    // 亲子出游
    const parCam = [
      {
        url: require("@/assets/zyzImg/yuan4.png"),
        title: "亲子出游",
      },
      {
        url: require("@/assets/zyzImg/yuan1.png"),
        title: "拍照/旅拍",
      },
      {
        url: require("@/assets/zyzImg/yuan2.png"),
        title: "公司团建",
      },
      {
        url: require("@/assets/zyzImg/yuan3.png"),
        title: "徒步登山",
      },
    ];
    //获取地址 
    let address = computed(()=>localStorage.getItem('cityName'))
    return {
      goBack,
      value,
      active,
      aimList: computed(() => store.state.travel.travelMainList.aimList),
      parCam,
      getPictureSrc,
      address,
      mainListRight: computed(
        () => store.state.travel.travelMainList.mainListRight
      ),
      mainListLeft: computed(
        () => store.state.travel.travelMainList.mainListLeft
      ),
    };
  },
};
// 头部 header
const header = () => {
  // 当前路由对象
  const router = useRouter();
  // 头部输入框
  let value = "";
  // 后退
  let goBack = function () {
    router.go(-1);
  };
  return {
    goBack,
    value,
  };
};
</script>
<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
#travel {
  header {
    background-image: url("../assets/zyzImg/图层 7.png");
    background-size: 180%;
    background-position: -80px -100px;
    background-repeat: no-repeat;
    width: 100%;
    height: 330px;
    padding: 10px;
    .topSec {
      padding: 20px 0;
      position: relative;
      width: 100%;
      .van-icon-arrow-left {
        position: absolute;
        left: -8px;
        top: 20px;
        color: #fff;
        font-size: 30px;
      }
      .van-search {
        width: 360px;
        margin: auto;
      }
      /deep/ .van-search__content {
        color: #909090;
        .van-search__label {
          color: #909090;
        }
        .van-field__control {
          color: #909090;
          font-weight: 500;
        }
      }
      .van-icon-arrow-down {
        color: #909090;
        font-size: 16px;
        position: absolute;
        left: 65px;
        top: 28px;
      }
    }
    .aim {
      padding-bottom: 10px;
      /deep/ .van-cell {
        background-color: transparent;
        .van-cell__title {
          span {
            color: #fff;
            font-size: 20px;
            font-weight: 800;
          }
        }
        /deep/ .van-tabs__nav {
          width: 200px;
          background-color: transparent;
        }
      }
    }
    .select {
      p {
        color: #fff;
        font-weight: 800;
        font-size: 16px;
        position: relative;
        span {
          margin-right: 10px;
        }
        .active {
          border-bottom: #000 5px solid;
        }
      }
      .content {
        margin-top: 10px;
        overflow: hidden;
        .tab1 {
          display: flex;
          overflow: auto;
          div {
            position: relative;
            flex: 1;
            flex-shrink: 1;
            margin-right: 10px;
            span {
              position: absolute;
              width: 80%;
              text-align: center;
              margin-left: 12px;
              border-radius: 10px;
              left: 0;
              bottom: 20px;
              font-size: 16px;
              background-color: rgba(255, 255, 255, 0.5);
            }
          }
        }
      }
    }
  }
  .parCam {
    > div {
      display: flex;
      font-size: 18px;
      text-align: center;
      div {
        margin: 0 5px;
        p {
          margin-bottom: 10px;
        }
      }
    }
    > p {
      margin: 5px 0;
      font-size: 16px;
      text-align: center;
      font-weight: 600;
      position: relative;
      span {
        font-weight: normal;
        font-size: 10px;
        position: absolute;
        color: #909090;
        top: 2px;
        right: 5px;
      }
    }
  }
  .newTrav {
    h2 {
      margin: 10px;
      font-size: 30px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      li {
        width: 45%;
        overflow: hidden;
        margin-bottom: 10px;
        position: relative;
        img {
          width: 100%;
        }
        p {
          font-size: 18px;
        }
      }
    }
    .list2 {
      margin: 10px 0 50px;
      overflow: hidden;
      > div {
        width: 45%;
        float: left;
        margin: 0 10px;
        > div {
          position: relative;
          margin-bottom: 20px;
          box-shadow: 0 0 4px #aaa;
          border-radius: 12px;
          overflow: hidden;
        }
        img {
          width: 100%;
        }
        .info {
          font-size: 16px;
          position: absolute;
          bottom: 0px;
          width: 100%;
          background-color: #fff;
          p {
            margin: 5px;
            > em {
              font-style: normal;
              position: absolute;
              right: 2px;
            }
          }
        }
      }
      .right {
        img {
          width: 100%;
          height: 240px;
        }
      }
      .left {
        height: 260px;
        img {
          height: 260px;
        }
      }
    }
    .bottom {
      margin: 50px 0;
      p {
        text-align: center;
        font-size: 20px;
        color: #909090;
      }
    }
  }
 /deep/ .van-search__field{
    margin-left: 20px;
  }
}
</style>
